package com.example.workmode;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.view.View;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;


/**
 * Demonstrates how to write an efficient list adapter. The adapter used in this example binds
 * to an ImageView and to a TextView for each row in the list.
 *
 * To work efficiently the adapter implemented here uses two techniques:
 * - It reuses the convertView passed to getView() to avoid inflating View when it is not necessary
 * - It uses the ViewHolder pattern to avoid calling findViewById() when it is not necessary
 *
 * The ViewHolder pattern consists in storing a data structure in the tag of the view returned by
 * getView(). This data structures contains references to the views we want to bind data to, thus
 * avoiding calls to findViewById() every time getView() is invoked.
 */

    public class TaskCursorAdapter extends ResourceCursorAdapter {


        public TaskCursorAdapter(Context context, int layout, Cursor c, int flags) {
            super(context, layout, c, flags);
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            TextView name = (TextView) view.findViewById(R.id.name);
            TextView duedate = (TextView) view.findViewById(R.id.duedate);
            name.setText(cursor.getString(cursor.getColumnIndex("name")));
            duedate.setText(cursor.getString(cursor.getColumnIndex("duedate")));
            
            
            name.setTextSize(22);
            duedate.setTextSize(15);
            
            if (cursor.getString(cursor.getColumnIndex("today")).equals("Y")) {
        		name.setTextColor(Color.RED);
            } else {
            	name.setTextColor(Color.BLACK);
            }

        }
        
    }

    	
    	
